//
//  MainViewController.m
//  宜居HD
//
//  Created by 张金国 on 16/4/25.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "SandboxViewController.h"
#import "Masonry.h"
#import "ZHSegmentView.h"
#import "Macro.h"

#import "ModelView.h"
#import "LocationView.h"
#import "ProgramView.h"

@interface SandboxViewController ()
/**
 *  自定义分段控件
 */
@property (nonatomic ,strong)ZHSegmentView          *segmentView;

/**
 *  建筑模型View
 */
@property (nonatomic ,strong)ModelView              *modelView;
/**
 *  区位沙盘View
 */
@property (nonatomic ,strong)LocationView           *locationView;
/**
 *  项目沙盘
 */
@property (nonatomic ,strong)ProgramView           *programView;

/**
 *  分段控件选中某个时的View
 */
@property (nonatomic ,strong)UIView           *showView;

@end

@implementation SandboxViewController

#pragma mark - LifeCircle
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kSandboxieVcBkColor;
    self.view.frame =kViewControllerScale;
    [self layoutUI];
}
#pragma mark - Private
/**
 *  布局大块view
 */
- (void)layoutUI {
    [self.segmentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(20);
        make.centerX.equalTo(self.view.mas_centerX);
        make.width.equalTo(self.view.mas_width).multipliedBy(1/3.0f);
        make.height.equalTo(self.view.mas_height).multipliedBy(1/15.0f);
    }];
    [self.showView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.segmentView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    [self.locationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.showView);
    }];
    [self.programView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.showView);
    }];

    [self.modelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.showView);
    }];

}

#pragma mark - Getter

- (ZHSegmentView *)segmentView {
    if (!_segmentView) {
        _segmentView = [[ZHSegmentView alloc]init];
        [_segmentView configForTitles:@[@"建筑模型",@"区位沙盘",@"项目沙盘"]];
        _segmentView.baseColor = [UIColor colorWithRed:0.285 green:0.810 blue:0.102 alpha:1.000];
        _segmentView.tintColor = [UIColor colorWithRed:1 green:0.38 blue:0.43 alpha:1];
        _segmentView.hasButtomLine = NO;
        _segmentView.leftAndRightLineEdge = 20;
        _segmentView.labelFont = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:20];
        [_segmentView setSelectItemAtIndex:0];
        __weak __typeof__(self) weakSelf = self;
        [_segmentView setDidSelectBlock:^(NSUInteger idx) {
            DDLogInfo(@"segment  select %@",@(idx));
            if (idx == 0) {
                [weakSelf.showView bringSubviewToFront:weakSelf.modelView];
            }else if (idx == 1) {
                [weakSelf.showView bringSubviewToFront:weakSelf.locationView];
            }else if(idx == 2 ){
                [weakSelf.showView bringSubviewToFront:weakSelf.programView];
            }
        }];
        [self.view addSubview:_segmentView];
    }
    return _segmentView;
}

- (ProgramView *)programView {
    if (!_programView) {
        _programView = [[ProgramView alloc]init];
        _programView.backgroundColor = [UIColor brownColor];
        [self.showView addSubview:_programView];
        
    }
    return _programView;
}
- (ModelView *)modelView {
    if (!_modelView) {
        _modelView = [[ModelView alloc]init];
        _modelView.backgroundColor = [UIColor colorWithRed:0.240 green:0.600 blue:0.510 alpha:1.000];
        [self.showView addSubview:_modelView];
     
    }
    return _modelView;
}
- (LocationView *)locationView {
    if (!_locationView) {
        _locationView = [[LocationView alloc]init];
        _locationView.backgroundColor = [UIColor blueColor];
        [self.showView addSubview:_locationView];
        
    }
    return _locationView;
}

- (UIView *)showView {
    if (!_showView) {
        _showView = [[UIView alloc]init];
        _showView.backgroundColor = [UIColor grayColor];
        [self.view addSubview:_showView];
    }
    return _showView;
}

@end
